<?php
namespace app\horoscope\controller;
use \app\check\controller\Check;
use \think\Db;
class Setting extends Check
{
    public function _initialize()
    {
        parent::filter_xss();
        if(!defined('IS_ACCESS_TOKEN_CHECKED'))
        {
            parent::check_func('check');
            parent::_initialize();// 接口调用验证
        }
    }

    /**
     * 八字设置更新
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function put()
    {
        $uid = $this->user['id'];

        $type = input('type/d');

        $start = input('start/d');

        $isset = Db::table('wechat_backup_07_18_14_43_00.app_horoscope_setting')->where('uid',$uid)->find();

        if(!empty($isset))
        {
            if(Db::table('wechat_backup_07_18_14_43_00.app_horoscope_setting')
                ->where('uid',$uid)->update(['type'=>$type,'start'=>$start]))
            {
                return json(['code'=>200,'msg'=>'切换成功！']);
            }
        }
        else
        {
            if(Db::table('wechat_backup_07_18_14_43_00.app_horoscope_setting')
                ->insertGetId(['uid'=>$uid,'type'=>$type,'start'=>$start]))
            {
                return json(['code'=>200,'msg'=>'切换成功！']);
            }
        }

        return json(['code'=>10400,'msg'=>'切换失败！']);
    }

}